package com.koron.order.defect.bean.po;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;

@Data
public class DefectRate {

    @ApiModelProperty(value = "部门id")
    private String deptId;

    @ApiModelProperty(value = "部门名称")
    private String deptName;

    @ApiModelProperty(value = "已处理消缺数")
    private Integer done;

    @ApiModelProperty(value = "应处理消缺数")
    private Integer todone;

    @ApiModelProperty(value = "消缺率")
    private Double defectRate;

    @ApiModelProperty(value = "一类（抢修）：已处理")
    private Integer sRescue;

    @ApiModelProperty(value = "一类（抢修）：应处理")
    private Integer tRescue;

    @ApiModelProperty(value = "一类抢修消缺率")
    private Double rescueDefectRate;

    @ApiModelProperty(value = "一类（常规）：已处理")
    private Integer sOneclass;

    @ApiModelProperty(value = "一类（常规）：应处理")
    private Integer tOneclass;

    @ApiModelProperty(value = "一类常规消缺率")
    private Double oneClassDefectRate;

    @ApiModelProperty(value = "二类：已处理")
    private Integer sTwoclass;

    @ApiModelProperty(value = "二类：应处理")
    private Integer tTwoclass;

    @ApiModelProperty(value = "二类消缺率")
    private Double twoClassDefectRate;

    @ApiModelProperty(value = "三类：已处理")
    private Integer sThreeclass;

    @ApiModelProperty(value = "三类：应处理")
    private Integer tThreeclass;

    @ApiModelProperty(value = "三类消缺率")
    private Double threeClassDefectRate;

    public Integer getDone() {
        return done == null ? 0 : done;
    }

    public Integer getTodone() {
        return todone == null ? 0 : todone;
    }

    public Integer getsRescue() {
        return sRescue == null ? 0 : sRescue;
    }

    public Integer gettRescue() {
        return tRescue == null ? 0 : tRescue;
    }

    public Integer getsOneclass() {
        return sOneclass == null ? 0 : sOneclass;
    }

    public Integer gettOneclass() {
        return tOneclass == null ? 0 : tOneclass;
    }

    public Integer getsTwoclass() {
        return sTwoclass == null ? 0 : sTwoclass;
    }

    public Integer gettTwoclass() {
        return tTwoclass == null ? 0 : tTwoclass;
    }

    public Integer getsThreeclass() {
        return sThreeclass == null ? 0 : sThreeclass;
    }

    public Integer gettThreeclass() {
        return tThreeclass == null ? 0 : tThreeclass;
    }

    /**
     * 获取总的消缺率
     * @return
     */
    public Double getDefectRate() {
        return convertToDouble(done,todone);
    }

    /**
     * 获取一类抢修消缺率
     * @return
     */
    public Double getRescueDefectRate() {
        return convertToDouble(sRescue,tRescue);
    }

    /**
     * 获取一类常规消缺率
     * @return
     */
    public Double getOneClassDefectRate() {
        return convertToDouble(sOneclass,tOneclass);
    }

    /**
     * 获取二类消缺率
     * @return
     */
    public Double getTwoClassDefectRate() {
        return convertToDouble(sTwoclass,tTwoclass);
    }

    /**
     * 获取三类消缺率
     * @return
     */
    public Double getThreeClassDefectRate() {
        return convertToDouble(sThreeclass,tThreeclass);
    }

    /**
     * 计算消缺率：消缺率：已处理/应处理*100%
     * @param value1
     * @param value2
     * @return
     */
    public Double convertToDouble(Integer value1, Integer value2){
        if (value2 == 0){
            return 0D;
        }
        BigDecimal b1 = new BigDecimal(value1.toString());
        BigDecimal b2 = new BigDecimal(value2.toString());
        // 保留两位小数
        return b1.divide(b2,2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100")).doubleValue();
    }



}
